package cn.tedu.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
     * 包含Tcc的三个操作方法
     *     第一阶段
     *      Try     -prepare()
     *      第二阶段
     *      Confirm  - commit()
     *      Cancel   - rollback()
      */
@LocalTCC
public interface OrderTccAction {
    @TwoPhaseBusinessAction(name = "OrderTccAction")
    boolean prepare(BusinessActionContext ctx,
//                    把id放入上下文对象，向第二阶段传递
                    @BusinessActionContextParameter(paramName = "id") Long id,
                    @BusinessActionContextParameter(paramName = "userId") Long userId,
                    @BusinessActionContextParameter(paramName = "productId") Long productId,
                    @BusinessActionContextParameter(paramName = "count") Integer count,
                    @BusinessActionContextParameter(paramName = "money") BigDecimal money);
    /**
     *为避免seata bug，不使用Order封装对象
     * 而是一个一个的接收订单数据
     * @return
     */
    boolean commit(BusinessActionContext ctx);
    boolean rollback(BusinessActionContext ctx);


}